#!/bin/sh

# flip apple mobile file integrity

log_dir="$HOME"/Library/"Application Support"/mySIMBL/logs
origargs=$(nvram boot-args)
origargs=${origargs/boot-args}
newargs=""
exec &>"$log_dir"/amfi.log

trim() {
    local var="$1"
    # remove leading whitespace characters
    var="${var#"${var%%[![:space:]]*}"}"
    # remove trailing whitespace characters
    var="${var%"${var##*[![:space:]]}"}"

#    var=$(echo "$var" | tr -s " ")
#    var=$(echo "$var" | sed -e 's,\\[trn],,g')

    echo "$var"
}


if [[ $origargs = *"amfi_get_out_of_my_way=1"* ]]; then
    newargs=${origargs/amfi_get_out_of_my_way=1/}
else
    newargs="$origargs amfi_get_out_of_my_way=1"
fi

newargs=$(trim "$newargs")

nvram boot-args="$newargs"

echo "Done"
